package com.web44.ssm.filter;

import com.web44.ssm.utils.ResponseVo;
import com.web44.ssm.utils.ServletUtils;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter;

import java.io.IOException;

/**
 * @Title: MyPermissionsAuthorizationFilter
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/2/19 17:06
 */
public class MyPermissionsAuthorizationFilter extends PermissionsAuthorizationFilter {

    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
        HttpServletResponse res = (HttpServletResponse)response;
        ServletUtils.renderString(res, ResponseVo.error("当前用户无权访问！"));
        return false;
    }
}
